package rxclass;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;

import java.util.List;
import java.util.ListIterator;

public class ConcatFunction implements Function<ListIterator<List<Object>>, ObservableSource<List<Object>>>{

    @Override
    public ObservableSource<List<Object>> apply(final ListIterator<List<Object>> listListIterator) throws Exception {
        return Observable.create(new ObservableOnSubscribe<List<Object>>() {
            @Override
            public void subscribe(ObservableEmitter<List<Object>> e) throws Exception {
                while (listListIterator.hasNext())
                {
                    listListIterator.next();
                }


                while (listListIterator.hasPrevious())
                {
                    e.onNext(listListIterator.previous());
                }
                e.onComplete();
            }
        });
    }
    public int foo(int x ,int y)
    {
        return x+y;
    }
}
